<?php

namespace App\Http\Controllers\Api;

use App\Integral;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;

class IntegralController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $data = Integral::latest()->where('user_id', Auth::id());
        $category = $request->get('category') ? $request->get('category') : 1;
        $data = $data->where('category', $category);
        if ($request->by_month) {
            $month = $request->month ? $request->month : date('m');
            $data = $data->whereMonth('created_at', $month);
        }
        return $data->get();
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\Integral  $integral
     * @return \Illuminate\Http\Response
     */
    public function show(Integral $integral)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Integral  $integral
     * @return \Illuminate\Http\Response
     */
    public function edit(Integral $integral)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Integral  $integral
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Integral $integral)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Integral  $integral
     * @return \Illuminate\Http\Response
     */
    public function destroy(Integral $integral)
    {
        //
    }
}
